<template>
  <div class="app-container">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-position="right"
      label-width="170px"
      style="margin-left: 30px">
      <div>
        <span>自动分账配置</span>
        <span class="form-word-hint">（订单收货完成后，是否进行自动分账）</span>
        <el-divider></el-divider>
      </div>
      <el-form-item label="自动分账配置" prop="settleFlag">
        <el-radio-group v-model="ruleForm.settleFlag">
          <el-radio
            v-for="item in statesList"
            :key="item.value"
            :label="item.value">
            {{ item.name }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <div class="fixed-bottom-20">
          <el-button type="primary" @click="submitForm('ruleForm')">
            立即提交
          </el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { Message } from "element-ui";
import { getCodeManager, codeToArray } from "@/api/all";
import { toEditOss, EditOss } from "@/api/system";
export default {
  name: "wxpayconfig",
  data() {
    return {
      statesList: [
        { value: "1", name: "退款到余额" },
        { value: "2", name: "原路退回" },
      ],
      ruleForm: {},
      rules: {},
    };
  },
  created() {
    getCodeManager("USE_YN", () => {
      this.statesList = codeToArray("USE_YN");
    });
    toEditOss().then((res) => {
      this.ruleForm = res.data.data.config;
      this.ruleForm.settleFlag = this.ruleForm.settleFlag + "";
    });
  },
  methods: {
    submitForm(ruleForm) {
      this.$refs[ruleForm].validate((valid) => {
        if (valid) {
          EditOss(this.ruleForm).then((res) => {
            if (!res.data.success) {
              Message.error(res.data.message);
              return;
            }
            Message.success("操作成功");
            return;
          });
        }
      });
    },
  },
};
</script>

<style></style>
